package com.xing.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.xing.model.UserInfo;
import com.xing.util.Util;

@Repository
public class LoginDao {

	@Resource
	private BaseDao baseDao;

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	
	public void testDao() {
		String sql = "select * from test";
		List<Object[]> list = 
				baseDao.getListBySql(sql, null, null);
		
		for (Object[] objs : list) {
			System.out.println(objs[0]);
		}
	}
	
	public UserInfo getUser(String userId, String password) {
		String hql = "from UserInfo where userId=:userId and password=:password";
		List<ParamModel> paramModelList = new ArrayList<ParamModel>();
		paramModelList.add(new ParamModel("userId", userId));
		paramModelList.add(new ParamModel("password", password));
		
		List<?> list = baseDao.getList("", hql, "", paramModelList);
		if (!Util.isEmpty(list)) {
			Object obj = list.get(0);
			if (obj instanceof UserInfo) {
				return (UserInfo) obj;
			}
		}
		
		return null;
	}
}
